***************************************
**** 	Table 7: NUTRITION 		****
***************************************

use "$dir/Data/analysis_main.dta", clear


*** Last 2 hours - no decline in effects by last slot of the day

gen halfl1 = ((slot>=5 & round<=2) | (slot>=6 & round==3) | (Hour_Start==1 & round>3)) if round<=15
gen halfl2 = ((slot>=5 & round<=2) | (slot>=6 & round==3) | (Hour_Start==12 & round>3) | (Hour_Start==1 & round>3)) if round<=15

cap drop *_hiw

foreach x of varlist l1fs l2fs halfl1 halfl2 slot{
	foreach y of varlist cash_postpay {
		gen `y'_`x' = `y'*`x'
		gen `y'_`x'_hiw = `y'_`x'*wealth_hi_avg
	}
	gen `x'_hiw = `x'*wealth_hi_avg
}

foreach x of varlist cash_postpay cash_announce{
	gen `x'_hiw = `x'*wealth_hi_avg
}

eststo clear


eststo r1: reghdfe n_productivity slot cash_postpay_slot cash_postpay cash_announce blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
		qui estadd scalar N1 = e(N)

eststo r2: reghdfe n_productivity slot cash_postpay_slot cash_postpay cash_announce slot_hiw cash_postpay_slot_hiw cash_postpay_hiw cash_announce_hiw wealth_hi_avg blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
		qui estadd scalar N1 = e(N)

eststo r3: reghdfe n_productivity cash_postpay_halfl2 cash_postpay cash_announce blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
		qui estadd scalar N1 = e(N)
		lincom cash_postpay + cash_postpay_halfl2
		qui estadd scalar coef1 = r(estimate)
		qui estadd scalar se1 = r(se)			
		qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))
		
eststo r4:reghdfe n_productivity cash_postpay_halfl1 cash_postpay cash_announce blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
		qui estadd scalar N1 = e(N)
		lincom cash_postpay + cash_postpay_halfl1
		qui estadd scalar coef1 = r(estimate)
		qui estadd scalar se1 = r(se)			
		qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))
		

		
// what people ate in the 2 days after cash


keep if round>3 & pid1==1		// collected after round 3


local k=1
foreach x in bf2d_avg rice2d_avg rice2dq veg2d_avg other2d_avg{
	*qui xi: reg `x' cash postonly2d i.round, cluster(pid)
	qui reghdfe `x' cash blhrprod_miss canget1k_miss ownland_miss bs_labor_7_miss bs_labor_30_miss future_fin_worry_miss, cluster(pid) a(roundgroup)
	qui estadd scalar N2 = e(N)
	eststo a`k'
	qui summarize `x' if cash==0 
	qui estadd scalar cont = r(mean)
	local `k++'
}

		
label var cash_postpay "Cash $\times$ Post-pay" 
label var cash_postpay_hiw "Cash $\times$ Post-pay $\times$ Higher wealth" 
label var cash_postpay_slot "Cash $\times$ Post-pay $\times$ Hour of day" 
label var cash_postpay_slot_hiw "Cash $\times$ Post-pay $\times$ Hour of day $\times$ Higher wealth" 
label var cash_postpay_halfl2 "Cash $\times$ Post-pay $\times$ Last 2 hours of day" 
label var cash_postpay_halfl1 "Cash $\times$ Post-pay $\times$ Last 1 hour of day" 


#delimit ;
local tablerow cash cash_postpay cash_postpay_slot cash_postpay_hiw cash_postpay_slot_hiw cash_postpay_halfl2 cash_postpay_halfl1 ;

esttab a1 a2 a3 a4 a5 r1 r2 r3 r4 using "$om/$t/Table_7.tex", 
    b(3) se booktabs star(* .1 ** .05 *** .01) nonotes nomtitles  
    replace label style(tex) gaps keep(`tablerow') order(`tablerow') 
    stats(cont N2 coef1 se1 pval1 N1, labels("Control group mean" "N: workers" "Coef: cash effect + interaction" "SE: cash effect + interaction" "P-val: cash effect + interaction" "N: worker-hours") fmt(%9.3fc %9.0fc %9.3fc %9.3fc %9.3fc %9.0fc)) 
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{tabular}
    {@{\extracolsep{4pt}}l*{10}{>{\centering\arraybackslash}m{1.5cm}}@{}} 
    \toprule 
	\multicolumn{1}{l}{}     &\multicolumn{5}{c}{\textbf{Breakfast Measures (Post-pay Period)}} &\multicolumn{4}{c}{\textbf{Hourly Production}}  \bigstrut       \\
    \cline{2-6} \cline{7-10} \addlinespace 
     &Had any breakfast & Ate rice 	&Amount of rice &Ate vegetables  &Ate any other item      \\
     ") ;
	
#delimit cr	
